package com.bbs.toutiao.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 描述:  统一返回状态码
 * 作者： zhangBin
 * 时间： 2023/9/5 20:49
 * 版本： 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result implements Serializable{
    //TODO 状态码 成功：200  失败：404
    private Integer code;

    //TODO 错误信息
    private String msg;

    //TODO 响应数据
    private Object data;

    /**
     * 响应成功
     * @param msg
     * @return
     */
    public static Result success(String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = 200;
        return result;
    }

    /**
     * 响应成功
     * @param msg
     * @param object
     * @return
     */
    public static  Result success(String msg,Object object) {
        Result result = new Result ();
        result.msg = msg;
        result.data = object;
        result.code = 200;
        return result;
    }

    /**
     * 响应失败
     * @param msg
     * @param code
     * @return
     */
    public static  Result error(Integer code,String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = code;
        return result;
    }

}
